package com.family.web.controller.pedigree;


import com.family.common.annotation.Log;
import com.family.common.core.controller.BaseController;
import com.family.common.core.domain.AjaxResult;
import com.family.common.core.page.TableDataInfo;
import com.family.common.enums.BusinessType;
import com.family.pedigree.domain.FamilyAlbum;
import com.family.pedigree.service.IFamilyAlbumService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 相簿表 前端控制器
 * </p>
 *
 * @author forever
 * @since 2024-11-25
 */

@RestController
@RequiredArgsConstructor
@RequestMapping("/family/album")
public class FamilyAlbumController extends BaseController {

    private final IFamilyAlbumService albumService;

    @Log(title = "添加相册", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyAlbum album) {
        albumService.add(album);
        return success();
    }

    @Log(title = "修改相册", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyAlbum album) {
        albumService.edit(album);
        return success();
    }

    @GetMapping("/list")
    public TableDataInfo list(FamilyAlbum album) {
        startPage();
        return getDataTable(albumService.lambdaQuery()
                .like(StringUtils.isNotBlank(album.getPhotoAlbum()), FamilyAlbum::getPhotoAlbum, album.getPhotoAlbum())
                .orderByDesc(FamilyAlbum::getCreateTime).list());
    }

    @Log(title = "删除相册", businessType = BusinessType.DELETE)
    @DeleteMapping("/{albumId}")
    public AjaxResult delById(@PathVariable Long albumId) {
        albumService.delById(albumId);
        return success();
    }

    @GetMapping("/{albumId}")
    public AjaxResult getInfo(@PathVariable Long albumId) {
        return success(albumService.getInfo(albumId));
    }

}
